package com.servlet;

import com.util.UtilJdbc;
import pom.Activity;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class Particulars extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("service");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String na=req.getParameter("name");

        UtilJdbc utilJdbc=new UtilJdbc();
        ResultSet set=utilJdbc.second(na);
        ArrayList arrayList=new ArrayList();


        try{
            while (set.next()){
                Activity activity=new Activity();
                activity.setId(set.getInt("id"));
                activity.setActname(set.getString("actname"));
                activity.setPlanner(set.getString("planner"));
                activity.setMember(set.getString("member"));
                activity.setActivityContent(set.getString("activityContent"));
                activity.setActid(set.getInt("actid"));
                activity.setActtime(set.getString("acttime"));
                activity.setActplace(set.getString("actplace"));
                arrayList.add(activity);
            }
            req.setAttribute("b",arrayList);
            req.getRequestDispatcher("/page/Particulars.jsp").forward(req, resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
